package cn.simon.free.ratelimiter.utils;

import cn.simon.free.ratelimiter.core.Rate;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * 所有方法的限流信息集合
 *
 * @author simon
 * @date 2019/12/26 17:00
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Slf4j
public class AllMethodRateLimiterUtils {

    private static final Map<String, Rate> rateLimiterMaps = Maps.newHashMap();

    private AllMethodRateLimiterUtils() {
    }

    /**
     * 取限流器
     *
     * @param key
     * @return
     */
    public static Rate get(String key) {
        if (rateLimiterMaps.containsKey(key))
            return rateLimiterMaps.get(key);
        return null;
    }

    /**
     * 生成限流器
     *
     * @param key
     * @param value
     */
    public static void put(String key, Rate value) {
        rateLimiterMaps.put(key, value);
    }

}
